<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/1/15
 * Time: 23:05
 */
namespace app\admin\logic;




use think\Db;
use think\exception\ValidateException;

class TaskLogic
{
    private static $new; //申请一个私有的静态成员变量来保存该类的唯一实例
    private function __construct() {

    }

    public static function instance () { //声明一个静态公共方法，供外部获取唯一实例
        if (!(self::$new instanceof self)) {
            self::$new = new self;
        }
        return self::$new;
    }

    /**
     * 修改任务时间后去更新，订单，众包费，税率的时间
     */
    public function edit($task_id, $time = 0) {
        if ($time == 0) {
            return true;
        }
        if (!$task_id) {
            return true;
        }

        $where['task_id'] = $task_id;
        Db::name('zbtask_order')->where($where)->update(['createtime' => $time, 'submittime'=> $time, 'paytime'=>$time]);
        Db::name('zbtask_money')->where($where)->update(['createtime'=> $time]);
        Db::name('zbtask_money_rate')->where(function ($query) use($where) {
            $task_money_ids = Db::name('zbtask_money')->where($where)->column('id');
            $query->where(['task_money_id'=>['in', $task_money_ids]]);
        })->update(['createtime'=> $time]);
        return true;
    }

    private function __clone() {} //声明私有的克隆方法，防止对象被克隆

    public function __sleep() { //重写__sleep方法，将返回置空，防止序列化反序列化获得新的对象
        return [];
    }
}